package com.flyduck.system.vo.user.trans;


import cn.hutool.core.bean.BeanUtil;
import com.flyduck.system.dao.SysDeptDao;
import com.flyduck.system.entity.SysDeptEntity;
import com.flyduck.system.entity.SysUserEntity;
import com.flyduck.system.vo.user.SysUserRespVO;
import com.google.common.base.Function;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


/**
 * @program: flyduck-platform
 * @description:
 * @author: flyduck
 * @create: 2021-02-01 12:42
 **/
public class SysUserEntityToSysUserRespVO implements Function<SysUserEntity, SysUserRespVO> {

    private SysDeptDao sysDeptDao;

    public SysUserEntityToSysUserRespVO(SysDeptDao sysDeptDao) {
        this.sysDeptDao = sysDeptDao;
    }


    @Override
    public SysUserRespVO apply(SysUserEntity entity) {
        List<SysDeptEntity> allDept = sysDeptDao.findAllDept();
        Map<Long, String> deptMaps = allDept.stream().collect(Collectors.toMap(SysDeptEntity::getId, SysDeptEntity::getDeptName));
        SysUserRespVO respVO = new SysUserRespVO();
        BeanUtil.copyProperties(entity,respVO);
        respVO.setId(entity.getId() + "");
        respVO.setDeptName(deptMaps.get(entity.getDeptId()));
        return respVO;
    }
}
